package org.triumphxx.rule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.triumphxx.rule.dto.NationalityRuleDTO;
import org.triumphxx.ruletemplate.AbstractRule;

import static org.triumphxx.constant.RuleConstant.MATCH_NATIONALITY_START;

/**
 * @author:triumphxx
 * @Date: 2024/1/8
 * @Time: 10:54
 * @微信公众号：思考集结处
 * @网站：http://blog.triumphxx.com.cn
 * @GitHub https://github.com/triumphxx
 * @Desc: 国籍校验规则
 **/
@Slf4j
public class NationalityRule extends AbstractRule {

    @Override
    public boolean execute(Object ruleDTO) {
        NationalityRuleDTO nationalityRuleDto = new NationalityRuleDTO();
        //对象属性赋值
        BeanUtils.copyProperties(ruleDTO, nationalityRuleDto);
        log.info("开始执行关于国籍的校验规则，传入的国籍信息为:{}",nationalityRuleDto.getNation());
        if (nationalityRuleDto.getNation().startsWith(MATCH_NATIONALITY_START)) {
            return true;
        }
        return false;
    }
}
